package com.fjp.heartguard.ui.report

import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.fjp.heartguard.app.Constants
import com.fjp.heartguard.app.base.BaseActivity
import com.fjp.heartguard.app.data.bean.ReportsType
import com.fjp.heartguard.app.ext.init
import com.fjp.heartguard.databinding.ActivityHistoryReportBinding
import com.fjp.heartguard.ui.report.adapter.HistoryReportAdapter
import com.fjp.heartguard.viewmodel.HistoryReportViewModel
import me.hgj.jetpackmvvm.ext.parseState

class HistoryReportActivity : BaseActivity<HistoryReportViewModel, ActivityHistoryReportBinding>() {
    private val historyReportAdapter = HistoryReportAdapter(arrayListOf()) {
        val intent = Intent()
        intent.putExtra(Constants.INTENT_REPORT_ID, it.id)
        setResult(RESULT_OK, intent)
        finish()
    }

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewModel = mViewModel
        mDatabind.click = ClickProxy()
        mViewModel.title.set("历史测评")
        val orderId = intent.getIntExtra(Constants.Intent_OLDER_ID, 0)
        mViewModel.getolderAllQuestionnaire(orderId, ReportsType.ALL.value)

        mDatabind.recyclerView.init(LinearLayoutManager(this, RecyclerView.VERTICAL, false), historyReportAdapter)

    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.history.observe(this) {
            parseState(it, {
                historyReportAdapter.addData(it)

            })
        }
    }

    inner class ClickProxy {

    }

}